home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / Sources / FWAbout.cpp next >
Encoding:
Text File  |  1996-08-16  |  11.9 KB  |  399 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWAbout.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWABOUT_H
  11. #include "FWAbout.h"
  12. #endif
  13.  
  14. #ifndef FWPART_K
  15. #include "FWPart.k"
  16. #endif
  17.  
  18. #ifndef FWPART_H
  19. #include "FWPart.h"
  20. #endif
  21.  
  22. #ifndef FWCONTXT_H
  23. #include "FWContxt.h"
  24. #endif
  25.  
  26. #ifndef FWICONSH_H
  27. #include "FWIconSh.h"
  28. #endif
  29.  
  30. #ifndef FWLINSHP_H
  31. #include "FWLinShp.h"
  32. #endif
  33.  
  34. #ifndef FWRESACC_H
  35. #include "FWResAcc.h"
  36. #endif
  37.  
  38. #ifndef FWRESSIN_H
  39. #include "FWResSin.h"
  40. #endif
  41.  
  42. #ifndef FWCFMRES_H
  43. #include "FWCFMRes.h"
  44. #endif
  45.  
  46. #ifndef FWMEMMGR_H
  47. #include "FWMemMgr.h"
  48. #endif
  49.  
  50. #ifndef FWTXTSHP_H
  51. #include "FWTxtShp.h"
  52. #endif
  53.  
  54. #ifndef FWTXTBOX_H
  55. #include "FWTxtBox.h"
  56. #endif
  57.  
  58. #ifndef FWMNUBAR_H
  59. #include "FWMnuBar.h"
  60. #endif
  61.  
  62. #ifndef SLODFSTR_H
  63. #include "SLODFStr.h"
  64. #endif
  65.  
  66. #ifndef SLODFSTR_K
  67. #include "SLODFStr.k"
  68. #endif
  69.  
  70. // ----- OpenDoc Includes -----
  71.  
  72. #ifndef SOM_ODFacet_xh
  73. #include <Facet.xh>
  74. #endif
  75.  
  76. #ifndef SOM_ODSession_xh
  77. #include <ODSessn.xh>
  78. #endif
  79.  
  80. //========================================================================================
  81. // Runtime Informations
  82. //========================================================================================
  83.  
  84. #ifdef FW_BUILD_MAC
  85. #pragma segment fwabout
  86. #endif
  87.  
  88. FW_DEFINE_AUTO(FW_CAboutFrame)
  89.  
  90. //========================================================================================
  91. // Constants for this module
  92. //========================================================================================
  93.  
  94. const ODID kOKButtonID = 1;
  95.  
  96. const FW_Fixed kDialogWidth         = FW_IntToFixed(350);
  97. const FW_Fixed kDialogHeight         = FW_IntToFixed(250);
  98. const FW_Fixed kLargeMargin         = FW_IntToFixed(20);
  99. const FW_Fixed kSmallMargin         = FW_IntToFixed(10);
  100. const FW_Fixed kIconSize             = FW_IntToFixed(32);
  101.  
  102. const FW_Fixed kButtonWidth         = FW_IntToFixed(80);
  103. const FW_Fixed kButtonHeight         = FW_IntToFixed(30);
  104.  
  105. const FW_Fixed kCopyrightHeight     = FW_IntToFixed(30);
  106. const FW_Fixed kDescriptionHeight     = FW_IntToFixed(200);
  107.  
  108. //========================================================================================
  109. // FW_About 
  110. //========================================================================================
  111.  
  112. void FW_About(Environment* ev, FW_CPart* part, FW_ResourceId id)
  113. {
  114.     FW_CPresentation* aboutDialogPresentation = NULL;
  115.     FW_VOLATILE(aboutDialogPresentation);
  116.     
  117.     short throwAt = 0;
  118.     FW_VOLATILE(throwAt);
  119.  
  120.     FW_TRY
  121.     {
  122.         ODTypeToken token = part->GetSession(ev)->Tokenize(ev, "Apple:ODF:Presentation:About");
  123.         aboutDialogPresentation = new FW_CPrivAboutPresentation(ev, part, token, id);
  124.     
  125.         throwAt = 1;
  126.         
  127.         part->PrivAddPresentation(aboutDialogPresentation);
  128.         
  129.         throwAt = 2;
  130.  
  131.         FW_CDialogFrame* aboutFrame = 
  132.             FW_CDialogFrame::NewModalDialog(ev, 
  133.                 part,                                    // Your part
  134.                 aboutDialogPresentation,                // Presentation
  135.                 FW_CPoint(kDialogWidth, kDialogHeight),    // Window size
  136.                 FW_kZeroPoint,                             // Window position
  137.                 FW_kStandardDialogPosition,                // Already made modal by NewModalDialog
  138.                 FW_CString(""));                        // Title for moveable dialog
  139.  
  140.         if (aboutFrame != NULL)
  141.         {
  142.             aboutFrame->SetDefaultButton(ev, kOKButtonID);
  143.             aboutFrame->GetWindow(ev)->Show(ev);
  144.         }
  145.         else 
  146.         {
  147.             part->PrivRemovePresentation(aboutDialogPresentation);
  148.             delete aboutDialogPresentation;
  149.         }
  150.     }
  151.     FW_CATCH_BEGIN
  152.     FW_CATCH_EVERYTHING()
  153.     {    
  154.         if (throwAt == 2)
  155.             part->PrivRemovePresentation(aboutDialogPresentation);
  156.         
  157.         delete aboutDialogPresentation;
  158.         
  159.         FW_THROW_SAME();
  160.     }
  161.     FW_CATCH_END
  162. }
  163.  
  164. //========================================================================================
  165. // class FW_CPrivAboutPresentation
  166. //========================================================================================
  167.  
  168. //----------------------------------------------------------------------------------------
  169. // FW_CPrivAboutPresentation::FW_CPrivAboutPresentation
  170. //----------------------------------------------------------------------------------------
  171.  
  172. FW_CPrivAboutPresentation::FW_CPrivAboutPresentation(Environment *ev, 
  173.                                                     FW_CPart* thePart, 
  174.                                                     ODTypeToken presentationType,
  175.                                                     FW_ResourceId id) :
  176.     FW_CPresentation(ev, thePart, NULL, presentationType),
  177.     fAboutId(id)
  178. {
  179. }
  180.  
  181. //----------------------------------------------------------------------------------------
  182. // FW_CPrivAboutPresentation::~FW_CPrivAboutPresentation
  183. //----------------------------------------------------------------------------------------
  184.  
  185. FW_CPrivAboutPresentation::~FW_CPrivAboutPresentation()
  186. {
  187. }
  188.  
  189. //----------------------------------------------------------------------------------------
  190. // FW_CPrivAboutPresentation::PrivNewFrame
  191. //----------------------------------------------------------------------------------------
  192.  
  193. FW_CFrame* FW_CPrivAboutPresentation::PrivNewFrame(Environment *ev,
  194.                                                     ODFrame* odFrame, 
  195.                                                     FW_Boolean fromStorage)
  196. {
  197. FW_UNUSED(fromStorage);
  198.     return FW_NEW(FW_CAboutFrame, (ev, odFrame, this, GetPart(ev), fAboutId));
  199. }
  200.  
  201. //========================================================================================
  202. // class FW_CAboutFrame 
  203. //========================================================================================
  204.  
  205. //----------------------------------------------------------------------------------------
  206. // FW_CAboutFrame::FW_CAboutFrame
  207. //----------------------------------------------------------------------------------------
  208.  
  209. FW_CAboutFrame::FW_CAboutFrame(Environment* ev, 
  210.                             ODFrame* odFrame, 
  211.                             FW_CPresentation* presentation, 
  212.                             FW_CPart* part,
  213.                             FW_ResourceId id)
  214.     : FW_CDialogFrame(ev, odFrame, presentation, part)
  215. {
  216.     FW_ResourceId iconID;
  217.     
  218.     // ----- Load the about resource
  219.     FW_CSharedLibraryResourceFile resFile(ev, part->GetPartInstance(ev));
  220.     
  221.     FW_PResource aboutResource(ev, resFile, id, FW_kAboutResourceType);
  222.     FW_PResourceSink sink(ev, aboutResource);
  223.     FW_CReadableStream stream(sink);
  224.     stream >> iconID;
  225.  
  226.     stream >> fPartNameFontSize;
  227.     stream >> fPartNameFontStyle;
  228.     stream >> fPartNameFontName;
  229.     stream >> fPartName;
  230.  
  231.     stream >> fVersionFontSize;
  232.     stream >> fVersionFontStyle;
  233.     stream >> fVersionFontName;
  234.     stream >> fVersion;
  235.  
  236.     stream >> fCreditsFontSize;
  237.     stream >> fCreditsFontStyle;
  238.     stream >> fCreditsFontName;
  239.     stream >> fCredits;
  240.  
  241.     // ----- Load the icon and set up the icon shape
  242.     FW_CRect bounds(kLargeMargin, kLargeMargin, FW_kFixed0, FW_kFixed0);
  243.  
  244.     FW_CIcon icon(resFile, iconID, 32);
  245.     fIconShape = FW_NEW(FW_CIconShape ,(icon, bounds));
  246.  
  247.     FW_END_CONSTRUCTOR
  248. }
  249.  
  250. //----------------------------------------------------------------------------------------
  251. // FW_CAboutFrame::~FW_CAboutFrame
  252. //----------------------------------------------------------------------------------------
  253.  
  254. FW_CAboutFrame::~FW_CAboutFrame()
  255. {
  256.     FW_START_DESTRUCTOR
  257.  
  258.     delete fIconShape;
  259. }
  260.  
  261. #ifdef FW_BUILD_MAC
  262. //----------------------------------------------------------------------------------------
  263. // FW_CAboutFrame::FacetAdded
  264. //----------------------------------------------------------------------------------------
  265.  
  266. void FW_CAboutFrame::FacetAdded(Environment* ev, ODFacet* facet, unsigned short facetCount)
  267. {
  268.     FW_CDialogFrame::FacetAdded(ev, facet, facetCount);
  269.     
  270.     if (facetCount == 1)
  271.     {
  272.         ODPlatformWindow platformWindow = facet->GetWindow(ev)->GetPlatformWindow(ev);
  273.         
  274.         WCTabHandle newColorTable = (WCTabHandle)FW_CMemoryManager::AllocateSystemHandle
  275.                                                                     (8+sizeof(ColorSpec));
  276.         (*newColorTable)->ctSize = 0;
  277.         (*newColorTable)->ctTable[0].value = wContentColor;
  278.         (*newColorTable)->ctTable[0].rgb = FW_CColor(FW_kRGBLightGray);
  279.         ::SetWinColor(platformWindow, newColorTable);
  280.     }
  281. }
  282. #endif
  283.  
  284. //----------------------------------------------------------------------------------------
  285. // FW_CAboutFrame::Draw
  286. //----------------------------------------------------------------------------------------
  287.  
  288. void FW_CAboutFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)
  289. {
  290.     // ----- Set drawing contect for the CFrame
  291.     FW_CViewContext vc(ev, this, odFacet, invalidShape);
  292.     
  293.     // ----- Draw the Icon -----
  294.     fIconShape->Render(vc);
  295.     
  296.     // ----- Draw the lines -----
  297.     FW_CInk lineColor(FW_kRGBDarkGray);
  298.     FW_Fixed pos = kLargeMargin+kIconSize+kSmallMargin;
  299.     FW_CLineShape::RenderLine(vc, 
  300.                             FW_CPoint(pos, kLargeMargin),
  301.                             FW_CPoint(pos, kDialogHeight - kLargeMargin),
  302.                             lineColor);
  303.     FW_CLineShape::RenderLine(vc, 
  304.                             FW_CPoint(kLargeMargin, pos),
  305.                             FW_CPoint(kDialogWidth - kLargeMargin, pos),
  306.                             lineColor);
  307.     
  308.     // ----- Draw the Part Name -----
  309.     FW_CInk standardInk(FW_kNormalTextInk);
  310.     
  311.     FW_CFont partNameFont(FW_kTimes, FW_kBold, FW_IntToFixed(24));
  312.     FW_CTextShape::RenderText(vc, 
  313.                             fPartName, 
  314.                             FW_CPoint(kLargeMargin+kIconSize+kSmallMargin+kSmallMargin, kLargeMargin+kIconSize), 
  315.                             FW_CFont(fPartNameFontName, fPartNameFontStyle, fPartNameFontSize),
  316.                             FW_kTextAlignLeft+FW_kTextAlignBaseLine,
  317.                             standardInk);
  318.  
  319.     // ----- Draw the Version -----
  320.     FW_CTextShape::RenderText(vc, 
  321.                             fVersion, 
  322.                             FW_CPoint(kDialogWidth-kLargeMargin, kLargeMargin+kIconSize), 
  323.                             FW_CFont(fVersionFontName, fVersionFontStyle, fVersionFontSize),
  324.                             FW_kTextAlignRight+FW_kTextAlignBaseLine,
  325.                             standardInk);
  326.  
  327.     // ----- Draw the user Credits -----
  328.     FW_CRect descriptionBox(kLargeMargin+kIconSize+kSmallMargin+kSmallMargin,
  329.                           kLargeMargin+kIconSize+kSmallMargin+kSmallMargin,
  330.                           kDialogWidth - kLargeMargin,
  331.                           kDialogHeight - kLargeMargin - kButtonHeight - kSmallMargin);
  332.     FW_CTextBoxShape::RenderTextBox(vc, 
  333.                             fCredits, 
  334.                             descriptionBox, 
  335.                             FW_CFont(fCreditsFontName, fCreditsFontStyle, fCreditsFontSize),
  336.                             FW_kTextBoxJustifyLeft+FW_kTextBoxJustifyTop+FW_kTextBoxWordWrap,
  337.                             standardInk);
  338.  
  339.     // ----- Draw the ODF Copyright -----
  340.     FW_CString odfCopyRight;
  341.     ::FW_PrivLoadODFString(ev, FW_kODFCopyright, odfCopyRight);
  342.     FW_CRect copyrightBox(kLargeMargin+kIconSize+kSmallMargin+kSmallMargin,
  343.                           kDialogHeight - kLargeMargin - kButtonHeight,
  344.                           kDialogWidth - kLargeMargin - kButtonWidth,
  345.                           kDialogHeight - kLargeMargin);
  346.     FW_CTextBoxShape::RenderTextBox(vc, 
  347.                             odfCopyRight, 
  348.                             copyrightBox, 
  349.                             FW_CFont("geneva", FW_kPlain, FW_IntToFixed(9)),
  350.                             FW_kTextBoxJustifyLeft+FW_kTextBoxJustifyTop+FW_kTextBoxWordWrap,
  351.                             standardInk);
  352.                             
  353. }
  354.  
  355. //----------------------------------------------------------------------------------------
  356. // FW_CAboutFrame::CreateSubViews
  357. //----------------------------------------------------------------------------------------
  358.  
  359. void FW_CAboutFrame::CreateSubViews(Environment* ev)
  360. {        
  361.     // ----- Create the OK button
  362.     FW_CRect buttonRect(kDialogWidth - kLargeMargin - kButtonWidth,
  363.                         kDialogHeight - kLargeMargin - kButtonHeight,
  364.                         kDialogWidth - kLargeMargin,
  365.                         kDialogHeight - kLargeMargin);
  366.     FW_CButton* okButton = FW_NEW(FW_CButton, (ev, this, kOKButtonID, buttonRect, 
  367.                                         FW_kPushButton, FW_CString("OK")));
  368. }
  369.  
  370. //----------------------------------------------------------------------------------------
  371. // FW_CAboutFrame::DoAdjustMenus
  372. //----------------------------------------------------------------------------------------
  373.  
  374. FW_Boolean FW_CAboutFrame::DoAdjustMenus(Environment *ev, FW_CMenuBar* menuBar, 
  375.                                     FW_Boolean hasMenuFocus, FW_Boolean isRoot)
  376. {
  377. FW_UNUSED(hasMenuFocus);
  378.     if (isRoot)
  379.         menuBar->EnableCommand(ev, kODCommandAbout, FALSE);
  380.  
  381.     return FALSE;
  382. }
  383.  
  384. //----------------------------------------------------------------------------------------
  385. //    FW_CAboutFrame::HandleNotification
  386. //----------------------------------------------------------------------------------------
  387.  
  388. void FW_CAboutFrame::HandleNotification(Environment *ev, const FW_CNotification& notification)
  389. {
  390.     FW_CPresentation* presentation = GetPresentation(ev);
  391.     FW_CPart* part = GetPart(ev);
  392.     
  393.     // Close and delete the dialog on OK
  394.     FW_CDialogFrame::HandleNotification(ev, notification);
  395.     
  396.     part->PrivRemovePresentation(presentation);
  397.     delete presentation;
  398. }
  399.